<template>
	<div class="TMB-warp">
		<div class="titler border-bottom">
			<span class="font-w fs16">CBM計画</span>
			<i class="el-icon-close" @click="CloseTables"></i>
		</div>
		<div class="middle-box">
			<div class="left-box border-right">
				<div class="row font-w border-bottom fs16">
					計画对象
				</div>
				<div class="row">
					<span class=" font-w mar8">装置</span>
					<span class="gray">
						{{ $store.state.plantName }}
					</span>
				</div>
				<div class="row border-bottom">
					<span class=" font-w mar8">{{ $t("message.plan.TBM.label_4") }}</span>
					<span class="mar8 gray">{{ $store.state.macType == 1 ? $t("message.plan.TBM.label_5") : '配管'
						}}</span>
					<el-input v-model="selectData.length" readonly class="mar8 tc"></el-input>
					<span>{{ $t("message.plan.TBM.label_6") }}</span>
				</div>
			</div>
			<div class="right-box">
				<div class="row font-w border-bottom fs16">
					計画設定条件
				</div>
				<div class="row font-w">
					周期設定係数
				</div>
				<div class="row">
					<el-checkbox v-model="Data.UseCoef" class="mar20">周期設定係数を考慮する。</el-checkbox>
				</div>
				<div class="row" style="padding-left: 70px;">
					<span>肉厚仕様に未設定時は、</span>
					<el-input class="mar8 tr" :class="Data.UseCoef ? 'orange' : ''" :disabled="!Data.UseCoef"
						v-model="Data.rbiNum" @input="Data.rbiNum = $setMyNum(Data.rbiNum, '1 - 1')"></el-input>
					<span>を採用</span>
				</div>
				<div class="row">
					<span class="mar8 font-w">最長検査周期</span>
					<el-input class="mar8 orange tr" v-model="Data.rbiMax"
						@input="Data.rbiMax = $setMyNum(Data.rbiMax, '2 - 0')"></el-input>
					<span>年</span>
				</div>
				<div class="row font-w">
					余寿命計算ルール
				</div>
				<!-- <div class="row">
					<el-checkbox v-model="Data.judgCrr[0]">環境設定で指定したルールを採用する。</el-checkbox>
				</div> -->

				<div class="row check-box">
					<el-checkbox v-model="Data.longj">長期</el-checkbox>
					<el-checkbox v-model="Data.shortj">短期</el-checkbox>
					<el-checkbox v-model="Data.square">最小二乗法</el-checkbox>
				</div>

				<div class="row border-top">
					<el-radio v-model="Data.UnitType" :label="1">定点単位</el-radio>
					<el-radio v-model="Data.UnitType" :label="2">グループ単位</el-radio>
				</div>
				<div class="row">
					<el-checkbox v-model="Data.SameGroup" :disabled="Data.UnitType == 1">同一グループ箇所も計画を立案する</el-checkbox>
				</div>
				<div class="row ">
					<el-checkbox v-model="Data.GroupPlan"
						:disabled="Data.UnitType == 1">グループ単位で計画時期を揃える(グループ内の最短値を採用)</el-checkbox>
				</div>
				<div class="row  border-top">
					<el-checkbox v-model="Data.PlanYMType">計画年月が当年以前の場合は、当月に計画を立案する。</el-checkbox>
				</div>

			</div>
		</div>
		<div class="footer border-top">
			<span class="font-w">上記の内容で良いですか?</span>
			<div>
				<el-button @click="CloseTables">Cancel</el-button>
				<el-button type="primary" @click="okFn">OK</el-button>
			</div>
		</div>
	</div>
</template>

<script>
import BASE from '@/utils/base'
import { getThckDeterPlanCBMPopData, ThckDeterPlanCBM } from '@/api/api';
import { getLocalStorage } from "@/utils/storage";
import { showLoading, hideLoading } from "@/utils/loading";
export default {
	name: "CMBPlan",
	props: {
		selectData: {
			type: Array
		},
	},
	data() {
		return {
			test: false,

			Data: {
				"rbiNum": "",
				"rbiMax": "",
				// "judgCrr": "",
				"longj": "",
				"shortj": "",
				"square": "",

				UseCoef: true,
				UseOpedt: true,
				UnitType: 1,
				SameGroup: false,
				GroupPlan: false,
				PlanYMType: false,
			}

		};
	},
	components: {},
	watch: {},
	methods: {
		CloseTables() {
			this.$emit('CloseTables')
		},

		async okFn() {
			console.log('this.Data', this.Data, this.selectData);
			// this.$emit('CloseTables');
			// this.$emit("reGetMTTableInfo");
			showLoading();
			let dataList = this.selectData.map(item => {
				return {
					dmgCode: Number(item.DMG_CODE),
					macCode: Number(item.MAC_CODE),
					posNo: Number(item.POS_NO),
					grnPosNo: Number(item.GRN_POS_NO),
				}
			})
			let dataJson = {
				dataList,
				PltCode: this.$store.state.pltCode,
				lan: parseInt(getLocalStorage("lang") == "1" ? 2 : 1),

				rbiNum: this.Data.rbiNum.toString(),
				rbiMax: this.Data.rbiMax.toString(),

				JudgCrr: `${Number(this.Data.longj)}${Number(this.Data.shortj)}${Number(this.Data.square)}`,

				longj: `${Number(this.Data.longj)}`,
				shortj: `${Number(this.Data.shortj)}`,
				square: `${Number(this.Data.square)}`,

				UseCoef: Number(this.Data.UseCoef),
				SameGroup: Number(this.Data.SameGroup),
				GroupPlan: Number(this.Data.GroupPlan),
				PlanYMType: Number(this.Data.PlanYMType),
				UnitType: Number(this.Data.UnitType),
			};

			console.log('dataJson', dataJson);
			let res = await ThckDeterPlanCBM(dataJson);
			hideLoading();
			if (!res) {
				return
			}
			if (res.data.code != 0) {
				this.$message({
					type: "error",
					message: res.data.msg
				})
				return
			}
			this.$message({
				type: 'success',
				message: res.data.msg
			})
			this.$emit('CloseTables');
			this.$emit("reGetMTTableInfo");
		},

		async getDataFn() {
			let dataJson = {};
			let res = await getThckDeterPlanCBMPopData(dataJson);

			// let judgCrr = [];
			// for (let i = 0; i < res.data.data.judgCrr.length; i++) {
			// 	judgCrr.push(res.data.data.judgCrr[i] === '1');
			// }

			Object.assign(this.Data, {
				...res.data.data,
				// judgCrr,
				longj: res.data.data.longj === "1",
				shortj: res.data.data.shortj === "1",
				square: res.data.data.square === "1",
			})
			console.log('this.Data', this.Data);
		},
		initFn() {
			this.getDataFn();
		}
	},
	created() { },
	mounted() {
		this.initFn();

		// if (BASE.IP == "http://192.168.33.200:8085") {
		// 	this.timeFormat = "yyyy-MM";
		// } else if (BASE.IP == "https://eng-dev-api.a-mis.com") {
		// 	this.timeFormat = "MM-yyyy";
		// } else if (BASE.IP == "https://demoapi.richtechcn.com") {
		// 	this.timeFormat = "yyyy-MM";
		// }
	},
	beforeDestroy() { },
	destroyed() { }
};
</script>
<style lang="scss" scoped>
.TMB-warp {
	width: 800px;
	height: 550px;
	background: rgb(255, 255, 255);
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translateX(-50%) translateY(-50%);
	box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.05),
		0px 9px 28px 0px rgba(0, 0, 0, 0.08), 0px 6px 16px -8px rgba(0, 0, 0, 0.15);
	z-index: 100;
}

.titler {
	height: 50px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 13px 24px;

	i {
		cursor: pointer;
	}
}

.middle-box {
	height: calc(100% - 100px);
	display: flex;

	.left-box {
		width: 281px;
		padding: 0 24px;
	}

	.right-box {
		width: calc(100% - 281px);
		padding: 0 24px;
	}

	.row {
		padding: 7px 0;
		display: flex;
		align-items: center;

		.el-input {
			width: 75px;
			height: 32px;

			::v-deep .el-input__inner {
				width: 75px;
				height: 100%;

			}
		}

		::v-deep .el-radio__label {
			font-weight: bold;

		}

		.ipt {
			width: 120px !important;
			height: 32px;
			margin-right: 8px;

			::v-deep .el-input__inner {
				width: 100%;
				height: 32px;
				padding: 0 8px 0 30px;
			}

			// ::v-deep .el-input__inner:focus {
			//   border: 1px solid #dcdfe6;
			// }
			::v-deep .el-input__icon {
				line-height: 32px;
				color: #909399;
			}

			::v-deep .el-input__suffix {
				display: none;
			}
		}
	}

	.check-box {
		border: 1px solid #f0f0f0;
		padding: 5px 20px;
		margin-bottom: 15px;
	}
}

.footer {
	height: 50px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 13px 24px;

	button {
		width: 82px !important;
		height: 32px;
		// background: #ffffff;
		// border: 1px solid #d9d9d9;
		// cursor: pointer;
		line-height: 0;
	}

	button:nth-child(2) {
		margin-left: 16px;
		// color: #ffffff;
		// background: #106ebe;
	}
}

.font-w {
	font-weight: bold;
}

.border-top {
	border-top: 1px solid #f0f0f0;
}

.border-bottom {
	border-bottom: 1px solid #f0f0f0;
}

.border-left {
	border-left: 1px solid #f0f0f0;
}

.border-right {
	border-right: 1px solid #f0f0f0;
}

.gray {
	color: #7B7B7B;
}

.mar8 {
	margin-right: 8px;
}

.mar20 {
	margin-right: 20px;
	;
}

.fs16 {
	font-size: 16px;
}

.orange {
	::v-deep .el-input__inner {
		background-color: #FEDDB1;
	}
}

.tr {
	::v-deep .el-input__inner {
		text-align: right;
	}
}

.tc {
	::v-deep .el-input__inner {
		text-align: center;
	}
}
</style>
